package com.kady.entity;

import java.util.List;

/**
 * \* Created with IntelliJ IDEA.
 * \* User: kady
 * \* Date: 2021/3/30
 * \* Time: 14:33
 * \* 千峰JAVA2101班
 * \* Description: 分页实体
 * \
 */
public class PageInfo<T> {
    //当前页
    private long page;
    //页索引
    private long pageIndex;
    //页大小
    private long pageSize = 6;
    //也总数
    private long pageTotal;
    //总条数
    private long totalCount;
    //数据列表
    private List<T> data;

    public PageInfo() {
    }

    public PageInfo(long page, long pageIndex, long pageSize, long pageTotal, long totalCount, List<T> data) {
        this.page = page;
        this.pageIndex = pageIndex;
        this.pageSize = pageSize;
        this.pageTotal = pageTotal;
        this.totalCount = totalCount;
        this.data = data;
    }

    public long getPage() {
        return page;
    }

    public void setPage(long page) {
        this.page = page;
    }

    public long getPageIndex() {
        return this.pageSize*(this.page-1);
    }

    public void setPageIndex(long pageIndex) {
        this.pageIndex = pageIndex;
    }

    public long getPageSize() {
        return pageSize;
    }

    public void setPageSize(long pageSize) {
        this.pageSize = pageSize;
    }

    public long getPageTotal() {
        long calPages = (int)(getTotalCount()/getPageSize());
        return getTotalCount()%getPageSize()>0?calPages+1:calPages;
    }

    public void setPageTotal(long pageTotal) {
        this.pageTotal = pageTotal;
    }

    public long getTotalCount() {
        return totalCount;
    }

    public void setTotalCount(long totalCount) {
        this.totalCount = totalCount;
    }

    public List<T> getData() {
        return data;
    }

    public void setData(List<T> data) {
        this.data = data;
    }

    @Override
    public String toString() {
        return "PageInfo{" +
                "page=" + page +
                ", pageIndex=" + pageIndex +
                ", pageSize=" + pageSize +
                ", pageTotal=" + pageTotal +
                ", totalCount=" + totalCount +
                ", data=" + data +
                '}';
    }
}
